package com.shitou.shitouproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.shitou.shitoucommons.annotation.CheckUserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.shitou.shitouproduct.entity.AttrGroupEntity;
import com.shitou.shitouproduct.service.AttrGroupService;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;

import javax.websocket.server.PathParam;


/**
 * 属性分组
 *
 * @author 石头人
 * @email 3076767823@qq.com
 * @date 2023-03-04 18:03:45
 */
@RestController
@RequestMapping("shitouproduct/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = attrGroupService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public RespBean info(@PathVariable("attrGroupId") Long attrGroupId){
        AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);

        return RespBean.success().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody AttrGroupEntity attrGroup){
        attrGroupService.save(attrGroup);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody AttrGroupEntity attrGroup){
        attrGroupService.updateById(attrGroup);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] attrGroupIds){
        attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return RespBean.success();
    }


    /**
     * 通过分类id进行查询
     * @param params
     * @param
     * @return
     */
    @RequestMapping("/listById")
    public RespBean queryPageByCategoryId(@RequestParam Map<String, Object> params){
        PageUtils page = attrGroupService.queryPageByCategoryId(params, null);

        return RespBean.success().put("page", page);
    }

}
